import Vue from "vue";
import VueRouter from "vue-router";
import {setStore} from "@/utils/storage"

Vue.use(VueRouter);

const router = new VueRouter({
    routes: [{
        path: '/',
        redirect: '/flow_chart'
    },
    {
        path:'/flow_chart',
        name: 'flow_chart',
        redirect: '/flow_chart/create',
        component: () => import('../layouts/RouteView'),
        children: [
            {
                path: '/flow_chart/create',
                name: 'create',
                component: () => import('../views/flowChart/Create') // 流程图创建
            },
            {
                path: '/flow_chart/edit',
                name: 'edit',
                component: () => import('../views/flowChart/Edit') // 流程图修改
            }
        ]
    },
]
})
router.beforeEach((to, from, next) => {
    if(to.query.localhost) setStore('localhost', JSON.stringify(to.query.localhost))
    if(to.query.modelId && to.query.modelId != 'null'){
        next({
            path:'/flow_chart/edit',
            query:{
                moduleId:to.query.modelId
            }
        })
    }
    next()
})
export default router